
$(document).ready(function() {
    function getCookieVal(offset) {
        var endstr = document.cookie.indexOf(";", offset);
        if (endstr == -1) {
            endstr = document.cookie.length;
        }
        return unescape(document.cookie.substring(offset, endstr));
    }
    function getCookie(name) {
        var arg = name + "=";
        var alen = arg.length;
        var clen = document.cookie.length;
        var i = 0;
        while (i < clen) {
            var j = i + alen;
            if (document.cookie.substring(i, j) == arg) {
                return getCookieVal(j);
            }
            i = document.cookie.indexOf(" ", i) + 1;
            if (i == 0) break;
        }
        return null;
    }
    function do_confirm(id){
        var r =confirm("您确定要删除文件  "+id+"？");
        if(r==true){
            var filename = id;
            var username = getCookie('username');
            $.post('myfile_del.php',{filename:filename,username:username},function(msg){
                var data =eval("("+msg+")");
                if(data['code']==1){
                    alert('文件删除成功！');
                    window.location.reload(true);
                }else{
                    alert('文件删除失败！请联系系统管理员！');
                }
            });         
        }

    }
    $.post('myfile_ck.php',{key:'zhonger'},function(msg){
        var data =eval("("+msg+")");
        var len =data.length;
        var str='';
        var username =getCookie('username');
        for(i=0;i<len;i++){
            if(data[i]['isPublic']==1){
                data[i]['isPublic']='公开';
            }else{
                data[i]['isPublic']='私有';
            }
            var url1="p/"+username+"/"+data[i].filename;
            var url2="mk_editor.php?filename="+data[i].filename;
            str+="<tr><td>"+(i+1)+"</td><td>"
                +data[i]['filename']+"</td><td>"
                +data[i]['isPublic']+"</td><td>"
                +data[i]['create_time']+"</td><td>"
                +data[i]['update_time']+"</td><td><a href='"+url1+"' target='_blank'>查看</a><a href='"+url2+"'>修改</a><a href='javascript:void(0)' class='del' id='"+data[i]['filename']+"'>删除</a></td</tr>";
            
        }
        $('#list').append(str);
        
        $('.del').click(function(){
            var id = $(this).attr('id'); 
            do_confirm(id);
        });
    }); 
})